<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="keywords" content="">
    <meta name="description" content="">
    <title>在线生成器</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link href="/static/libs/antd.min.css" th:href="@{/libs/antd.min.css}" rel="stylesheet"/>
    <link href="/static/libs/ivonline.min.css" th:href="@{/libs/ivonline.min.css}" rel="stylesheet"/>

    <style>
        .ivz-gen-modal .ant-form-item { /*代码生成器弹框表单样式*/
            margin: 0px 0px 8px!important;
        }
        #online,.ant-spin-nested-loading,.ant-spin-container {
            width: 100%;
            height: 100%;
        }
    </style>
</head>
<body>
    <div id="online">
        <a-spin :spinning="spinning" :tip="tip">
            <ivz-online :save-callback="saveCallback" :init-callback="initCallback"></ivz-online>
        </a-spin>
    </div>
</body>
<script th:inline="javascript">
    var izCtxValue = [[${#request.contextPath}]]; // 当前应用上下文路径
    var izStxValue = izCtxValue; // 静态资源上下文路径
    window.ivzOnlineConfig = {
        izCtx: izCtxValue, // 访问路径的 context_path
        izStx: izStxValue, // 访问静态资源的context_path
        // dictLabelField: 'name', // 字典名称字段
        // dictValueField: 'type', // 字典值字段
        dictListUrl: '/ovt/dictList', // 获取字典列表(模拟地址)
        dictUrl: '/ovt/listByType', // 获取字典数据url(模拟地址)
        iconUrl: '//at.alicdn.com/t/font_1174643_hp1sy1rmyd5.js', // icon链接地址, 采用阿里图标库
    }
</script>

<script src="/static/libs/mock.js" th:src="@{/libs/mock.js}"></script>
<script src="/static/libs/polyfill.min.js" th:src="@{/libs/polyfill.min.js}"></script>
<script src="/static/libs/vue.min.js" th:src="@{/libs/vue.min.js}"></script>
<script src="/static/libs/axios.min.js" th:src="@{/libs/axios.min.js}"></script>
<script src="/static/libs/moment.min.js" th:src="@{/libs/moment.min.js}"></script>
<script src="/static/libs/zh-cn.js" th:src="@{/libs/zh-cn.js}"></script>
<script src="/static/libs/antd.min.js" th:src="@{/libs/antd.min.js}"></script>
<script src="/static/libs/ivonline.min.js" th:src="@{/libs/ivonline.min.js}"></script>

<script>
    new Vue({
        el: '#online',
        data: {
            detail: null,
            tip: '数据提交中...',
            spinning: false,
        },
        created() {

        },
        methods: {
            initCallback() {
                let urlParam = this.$utils.getUrlParam(location.href);
                if(urlParam.id) {
                    let id = urlParam.id;
                    if(id.indexOf('#') > 0) {
                        id = id.substring(0, id.indexOf('#'))
                    }
                    return new Promise((resolve, reject) => {
                        this.$http.get("/develop/genOnline/detail", {params: {id}}).then(resp=>{
                            let detail = this.detail = resp.data;
                            resolve({metas:  detail.metas, permMetas: detail.permMetas, viewConfig: detail.viewConfig});
                        }).catch(resp=>{
                            reject(resp);
                        });
                    })
                } else {
                    return new Promise((resolve, reject) => {});
                }

            },
            saveCallback(config) {
                this.spinning = true;
                if(this.detail) {
                    this.detail.metas = config.metas;
                    this.detail.permMetas = config.permMetas;
                    this.detail.viewConfig = config.viewConfig;

                    let model = config.viewConfig.model;
                    this.detail.name = model.tableName;
                    this.detail.remark = model.comment;

                    this.$http.post("/develop/genOnline/edit", this.detail).then(resp=>{
                        this.$msg.successMessage("修改数据成功");
                    }).catch(reason=>{
                        this.$msg.errorMessage(reason);
                    }).finally(()=>{
                        this.spinning = false;
                    })
                } else {
                    let model = config.viewConfig.model;
                    config.name = model.tableName;
                    config.remark = model.comment;
                    this.$http.post("/develop/genOnline/add", config).then(resp=>{
                        this.$msg.successMessage("新增数据成功");
                    }).catch(reason=>{
                        this.$msg.errorMessage(reason);
                    }).finally(()=>{
                        this.spinning = false;
                    })
                }
            }
        }
    });
</script>
</html>
